/*
 *   Copyright (c) 2010 Sonrisa Informatikai Kft. All Rights Reserved.
 * 
 *  This software is the confidential and proprietary information of
 *  Sonrisa Informatikai Kft. ("Confidential Information").
 *  You shall not disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Sonrisa.
 * 
 *  SONRISA MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 *  THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 *  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 *  PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SONRISA SHALL NOT BE LIABLE FOR
 *  ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 *  DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package com.zh.jbet.core.tournament.entity;

import com.zh.jbet.core.entity.Bet;
import com.zh.jbet.core.entity.Player;
import com.zh.jbet.core.scorer.TargetGameScorer;
import com.zh.jbet.core.tournament.scorer.MatchBetScorer;
import javax.persistence.Basic;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

/**
 *
 * @author sonrisa
 */
@TargetGameScorer(scorer=MatchBetScorer.class)
public class MatchResultBet implements Bet {
    private Long id;
    private Long playerGameId;
    private Long gameId;
    private Player player;
    private Integer homeGoalNo;
    private Integer awayGoalNo;
    private Integer point;

    @Id
    @SequenceGenerator(name = "S_RESULT_BET", sequenceName = "S_RESULT_BET", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_TMRESULT")
    @Override
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }

    @Basic
    public Integer getHomeGoalNo() {
        return homeGoalNo;
    }
    public void setHomeGoalNo(Integer homeGoalNo) {
        this.homeGoalNo = homeGoalNo;
    }
    @Basic
    public Integer getAwayGoalNo() {
        return awayGoalNo;
    }
    public void setAwayGoalNo(Integer awayGoalNo) {
        this.awayGoalNo = awayGoalNo;
    }

    @Basic
    @Override
    public Integer getPoint() {
        return point;
    }
    @Override
    public void setPoint(Integer point) {
        this.point = point;
    }

    @Basic
    @Override
    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    @Basic
    @Override
    public Long getPlayerGameId() {
        return playerGameId;
    }

    public void setPlayerGameId(Long playerGameId) {
        this.playerGameId = playerGameId;
    }

    @Basic
    @Override
    public Long getGameId() {
        return gameId;
    }
    public void setGameId(Long gameId) {
        this.gameId = gameId;
    }

    @Transient
    @Override
    public boolean isFilled() {
        return homeGoalNo != null && awayGoalNo != null;
    }
    @Transient
    public boolean isHomeWin() {
        return homeGoalNo > awayGoalNo;
    }
    @Transient
    public boolean isAwayWin() {
        return awayGoalNo > homeGoalNo;
    }

    @Override
    public String toString() {
        return isFilled() ? homeGoalNo + " : " + awayGoalNo : null;
    }
}
